/*
 * Create in 2013-4-20 上午11:24:44.
 */
package kit4j.app.notepad.command;

import java.awt.SystemTray;

import kit4j.app.notepad.ui.comp.NotepadTrayIcon;
import kit4j.common.command.FullCommand;

import com.google.inject.Inject;

/**
 * 
 * @author MiniKnife
 * 
 */
public class ExitCommand implements FullCommand {

	private NotepadTrayIcon trayIcon;

	/**
	 * @see kit4j.common.command.RedoableCommand#redo()
	 */
	@Override
	public void redo() throws Exception {
		execute();
	}

	/**
	 * @see kit4j.common.command.Command#execute()
	 */
	@Override
	public void execute() throws Exception {
		if (SystemTray.isSupported()) {
			SystemTray.getSystemTray().remove(getTrayIcon());
		}
		System.exit(0);
	}

	/**
	 * @see kit4j.common.command.UndoableCommand#undo()
	 */
	@Override
	public void undo() throws Exception {
		// Can't undo if executed
	}

	public NotepadTrayIcon getTrayIcon() {
		return trayIcon;
	}

	@Inject
	public void setTrayIcon(NotepadTrayIcon trayIcon) {
		this.trayIcon = trayIcon;
	}

}
